//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __DRIVER_H__
#define __DRIVER_H__

#include <eltypes.h>
_ELASTOS_NAMESPACE_USING

//
//  Driver
//
class CDeviceDriver : public IDeviceDriver
{
public:
    CARAPI_(PInterface) Probe(
         /* [in]  */ REIID riid);

    CARAPI_(UInt32) AddRef(void);

    CARAPI_(UInt32) Release(void);

    CARAPI Aggregate(
        /* [in] */ AggrType aggrType,
        /* [in] */ PInterface pObject);

    CARAPI GetDomain(
         /* [out] */ PInterface *ppObj);

    CDeviceDriver()            {}
    virtual ~CDeviceDriver()   {}

    virtual void Dispose() = 0;

protected:
    Interlocked     m_cRef;
};

///////////////////////////////////////////////////////////
#define EVENT_KEYPAD    1
#define EVENT_TOUCH     2

#define EVENT_KEYSOUND          3   //key sound
#define EVENT_TOUCHSOUND        4   //touch-panel sound

#define EVENT_MiniSD    10  //for sdcard insert/remove event

#define EVENT_PAUSEBREAK     12 //special keypress event for auto/stopplay

#define EVENT_MAX       128

#define HOOK_MAINCRTSTARTUP 20  //for user proc before maincrtstartup, gdiserve
#define HOOK_LOADMODULE     21  //for load extern dllmodule or services etc.
#define HOOK_INPUTEVENT     23  //for Record keypad & touch input event
#define HOOK_UNLOADMODULE   24  //
#define HOOK_MOUSEMOTION    25  //
#define HOOK_CREATEOBJECT   29  //
#define HOOK_INPUTNOTIFY    30  //

//36-82 was used for timer
#define EVENT_TIMER0    36   //channel 0,ms
#define EVENT_TIMER1    37   //channel 1,s
#define EVENT_TIMER2    38   //channel 2,min
#define EVENT_TIMER3    39   //channel 3,h
#define EVENT_TIMER     40   //user timer start
#define EVENT_POWER     80   //power manager queue
#define EVENT_USER      81   //user queue
#define EVENT_IDLE      82   //cpu idle mode
#define EVENT_INPUT     83   //input event

typedef struct {
    int eType;//Event type
    int Size;//Queue element size
    int Len;//Queue array length
}QueueInfo;
void EnQueueProc(int eType, int nCode, void *pParam);

typedef void (*TimerCallBackProc)(void * pvArg);
typedef struct {
    TimerCallBackProc pCallbackProc;
    void              * pvArg;
    int               eType;//QueueNo
    UInt32             Resolution;
    UInt32             Interval;
}TimerInfo;

extern IDeviceDriver * g_pEventQueues;

int AddNotify(int EventType, const void *pNotiProc);
void NotifyByIsr(int eType, int nCode, void *pParam);
void EventNotify(int eType, int nCode, void *pParam);

//returns the number of milliseconds since boot time.
int GetTimestamp();

EXTERN_C int __stdcall _SysSetHook(int hHook, const void *pHookProc);
EXTERN_C void __stdcall _SysCallNextHook(int hHook, int nCode, void *pParam);
EXTERN_C void __stdcall _SysUnhook(int hHook);

#endif //__DRIVER_H__
